package org.hot100_1;


import java.util.*;

public class leetcode2 {
    public List<List<String>> groupAnagrams(String[] strs) {

        Map<String,List<String>> map = new HashMap<>();

        for (String str:strs) {
            char[] chars = str.toCharArray();
            Arrays.sort(chars);
            String sameStr = new String(chars);

            List<String> strList = map.getOrDefault(sameStr, new ArrayList<>());
            strList.add(str);
            map.put(sameStr,strList);
        }

        return new ArrayList<>(map.values());
    }
}
